﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using BattleNet.DataAccess.SourceProviders.Interface;
using Ninject;

namespace BattleNet.DataAccess.SourceProviders.Web
{
    public class WebSourceProvider : ISourceProvider<string>
    {
        private WebRequest _request;
        
        
        public WebSourceProvider(WebRequest request)
        {
            _request = request;
        }

        public WebSourceProvider(string uri)
        {
            _request = WebRequest.Create(uri);
        }

        public string Provide()
        {
            var response = _request.GetResponse();
            using (Stream responseStream = response.GetResponseStream())
            {
                StreamReader reader = new StreamReader(responseStream);
                string stringResponse = reader.ReadToEnd();
                return stringResponse;
            }
        }
    }
}
